<?php

namespace app\admin\model;

use think\Model;
use think\Db;

class Jobs extends Model
{
	//新增工作
	public function addjobs($param)
	{
        $title = Jobs::get(['title'=>$param['title']]);
        if(isset($title)){
        	$this->error = '已存在相同名称的工作!';
        	return false;
        }
        $this->startTrans();
		try{
			$this->data($param)->allowField(true)->save();
			$this->commit();
			return true;
		}catch(\Exception $e){
			$this->rollback();
			$this->error = '添加失败';
			return false;
		}
	}

	//更新工作
	public function updatejobs($param)
	{
		$jobs = Jobs::get($param['id']);
		$this->startTrans();
		try{
			$jobs['title'] = $param['title'];
			$jobs['recagency'] = $param['recagency'];
			$jobs['edubackground'] = $param['edubackground'];
			$jobs['jobprice'] = $param['jobprice'];
			$jobs['yearofwork'] = $param['yearofwork'];
			$jobs['position'] = $param['position'];
			$jobs['jobdes'] = $param['jobdes'];
			$jobs->allowField(true)->save();
			$this->commit();
			return true;
		}catch(\Exception $e){
			$this->rollback();
			$this->error = '更新失败';
			return false;
		}
	}

	//删除工作
	public function deletejobs($param)
	{
		$jobs = Jobs::get($param);
		$this->startTrans();
		try{
			$jobs->delete();
			$this->commit();
			return true;
		}catch(\Exception $e){
			$this->rollback();
			$this->error = '删除失败';
			return false;
		}
	}
	//发布工作
	public function fabujobs($param)
	{
		$jobs = Jobs::get($param);
		$this->startTrans();
		try{
			$jobs['status'] = 1;
			$jobs->allowField(true)->save();
			$this->commit();
			return true;
		}catch(\Exception $e){
			$this->rollback();
			$this->error = '删除失败';
			return false;
		}
	}
	//取消发布
	public function canceljobs($param)
	{
		$jobs = Jobs::get($param);
		$this->startTrans();
		try{
			$jobs['status'] = 0;
			$jobs->allowField(true)->save();
			$this->commit();
			return true;
		}catch(\Exception $e){
			$this->rollback();
			$this->error = '删除失败';
			return false;
		}
	}
}